

import { useLocation} from "react-router-dom"
// 高阶组件 -- 路由守卫

import Loginpass from "../views/loginpass/loginpass"
import Loginregister from "../views/loginregister/loginregister";

export function routerBeforeEach(DefaultComponent){

    
    
    // 函数组件
    return function(props){
        let location = useLocation();

        // let navigate = useNavigate();

        console.log("高阶组件调用--验证是否登录");
        console.log(location);

        let login = window.localStorage.getItem("token");
        if(!login){ //没有登录
            // navigate("/login");
            if(location.pathname == "/loginregister"){
                return (<Loginregister {...props}/>);

            }else{
                return (<Loginpass {...props}/>);
            }

            

        }else{
            console.log("组件==>",DefaultComponent);
            return (<DefaultComponent {...props} />)
        }

    }



}